<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('流程审批')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: summernote-css" />
</head>
<body class="white-bg">
<div class="col-sm-8">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-sjcontract-add" th:object="${obj}">
    	<input name="approvename" id="approvename" type="hidden" th:value="${approvename}" />
            <input name="gcProjectid" type="hidden" th:field="*{gcProjectid}" />
            <input type="hidden" id="zlwj" name="zlwj" th:field="*{zlwj}" />
            <input type="hidden" id="zlwjvo" name="zlwjvo" th:value="${zlwjvo}" />
            <input type="hidden" id="approvename" name="approvename" th:value="${approvename}" />
            <div class="form-group">    
                <label class="col-sm-2 control-label is-required">对接部门：</label>
                <div class="col-sm-4">
                    <input name="dept" class="form-control" type="text" th:field="*{dept}" autoComplete="off" readonly="readonly" required>
                    <input name="deptId" th:field="*{deptId}" type="hidden">
                </div>
                <label class="col-sm-2 control-label is-required">对接人：</label>
                <div class="col-sm-4">
                    <input name="owner" class="form-control" th:field="*{owner}" readonly="readonly" type="text" autoComplete="off" required>
                	<input name="ownerId" th:field="*{ownerId}" type="hidden">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-2 control-label">项目名称：</label>
                <div class="col-sm-4">
                    <input name="projectName" class="form-control" type="text" th:field="*{projectName}" readonly="readonly" >
                </div>
                <label class="col-sm-2 control-label">建设单位：</label>
                <div class="col-sm-4">
                    <input name="clientName" class="form-control" type="text" th:field="*{clientName}" readonly="readonly" >
                </div>
            </div>
            <div class="form-group">  
            	<label class="col-sm-2 control-label">编号：</label>
                <div class="col-sm-4">
                    <input name="orderNo" class="form-control" type="text" th:field="*{orderNo}" readonly="readonly">
                </div>  
                <label class="col-sm-2 control-label">签发日期：</label>
                <div class="col-sm-4">
                    <div class="input-group date">
                        <input name="qfAt" readonly="readonly" th:value="${#dates.format(obj.qfAt, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-2 control-label">设计负责人：</label>
                <div class="col-sm-4">
                    <input name="sjfzr" class="form-control" type="text" th:field="*{sjfzr}" readonly="readonly">
                </div>
                <label class="col-sm-2 control-label">专业负责人：</label>
                <div class="col-sm-4">
                    <input name="zyfzr" class="form-control" type="text" th:field="*{zyfzr}" readonly="readonly">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-2 control-label">审核人：</label>
                <div class="col-sm-4">
                    <input name="spr" class="form-control" type="text" th:field="*{spr}" readonly="readonly">
                </div>
                <label class="col-sm-2 control-label">校对负责人：</label>
                <div class="col-sm-4">
                    <input name="jdfzr" class="form-control" type="text" th:field="*{jdfzr}" readonly="readonly">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-2 control-label">项目负责人：</label>
                <div class="col-sm-4">
                    <input name="xmfzr" class="form-control" type="text" th:field="*{xmfzr}" readonly="readonly">
                </div>
                <label class="col-sm-2 control-label">出图盖章人：</label>
                <div class="col-sm-4">
                    <input name="sdfzr" class="form-control" type="text" th:field="*{sdfzr}" readonly="readonly">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">附件：</label>
                <div class="col-sm-10" style="margin-top: 8px;" id="zlwjlink">
                </div>
            </div>
        <div class="form-group">
            <label class="col-sm-2 control-label ">审批结果：</label>
            <div class="col-sm-4">
                <label class="radio-box">
                    <input type="radio" checked="" value="true" name="level3approve">同意</label>
                <label class="radio-box">
                    <input type="radio" value="false" name="level3approve">拒绝</label>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label is-required">审批意见：</label>
            <div class="col-sm-10">
                <textarea rows="5" name="fwshyj" class="form-control" required></textarea>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-3 col-sm-offset-3">
                <input type="hidden"  name="taskid" id="taskid" th:value="${taskid}">
                <input type="hidden"  name="status" id="status" th:value="2">
                <input type="hidden"  name="id" id="id" th:value="${obj.id}">
                <button class="btn btn-primary" onclick="submitHandler()" type="button"><i class="fa fa-check"></i>&nbsp;提交</button>
            </div>
        </div>
    </form>
</div>
</div>
<div id="ibox-content" class="col-sm-4">
    <div id="vertical-timeline" class="vertical-container dark-timeline">
    </div>
</div>
</body>
<th:block th:include="include :: footer" />
<th:block th:include="include :: datetimepicker-js" />
<th:block th:include="include :: summernote-js" />
<script th:inline="javascript">
    var prefix = ctx + "task/manage"
    $("#form-sjcontract-add").validate({
        focusCleanup: true
    });

    function submitHandler() {
    	if ($.validate.form()) {
        var taskid = $("#taskid").val();
        var check = document.querySelector("input[name='level3approve']:checked").value;
        if(check=="false"){
        	$("#status").val(4);
        }else{
        	$("#status").val(2);
        }
        var comment = $("textarea[name=fwshyj]").val();
        
        $.operate.save("edit4check", $('#form-sjcontract-add').serialize(), function(){
        	var json = {"level3approve": check, "level4": $("#approvename").val(), "comment": comment};
	        $.ajax({
	            url : prefix + "/completeTask/" + taskid,
	            type : "POST",
	            data : JSON.stringify(json), //转JSON字符串
	            dataType: 'json',
	            contentType:'application/json;charset=UTF-8', //contentType很重要
	            success : function(result) {
	                $.modal.msg("办理成功");
	                const parent = window.parent;
	                // 我的待办
	                const myToDoIframe = parent.document.querySelector("iframe[src='/task/manage/mytask']");
	                // 我的全部待办
	                const myAllToDoIframe = parent.document.querySelector("iframe[src='/task/manage/alltasks']");
	                myToDoIframe && myToDoIframe.contentWindow.location.reload(true);
	                myAllToDoIframe && myAllToDoIframe.contentWindow.location.reload(true);
	                $.modal.closeTab();
	            }
	        });
	        
        });
    	}
    }

    $(document).ready(function(){
        // 获取时间轴
        $.get(prefix + "/history/" + $("#taskid").val(), function(data){
            for (var a = 0; a < data.length ; a++) {
                $("#vertical-timeline").append("<div class=\"vertical-timeline-block\"><div class=\"vertical-timeline-icon lazur-bg\">" +
                    "<i class=\"fa fa-briefcase\"></i></div>" +
                    "<div class=\"vertical-timeline-content\">" +
                    "<span class=\"vertical-date\">开始 <small>" + data[a].startTime + "</small></span><br>" +
                    "<h2><b>" + data[a].assignee + ":</b>" + data[a].taskName + "</h2>" +
                    "<p>" + (data[a].comment || "-") + "</p>" +
                    "<span class=\"vertical-date\">结束 <small>" + (data[a].endTime || "-") + "</small></span>" +
                    "</div>" +
                    "</div>");
            }
        });
    });
    
    $("input[name='qfAt']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });
    
    $(function() {
		var zilwj = $("#zlwjvo").val();
    	
    	var n=zilwj.split(",");
    	for(var i=0;i<n.length;i++){
//     		var url = "http://lkgnews.cn:8012/onlinePreview?url="+encodeURIComponent(Base64.encode(n[i]));
    		var url = n[i];
    		$("#zlwjlink").append("<a href='"+url+"' target='_blank' >"+n[i]+"</a><br>");
    	}
    	
    	
    	$('.summernote').summernote({
           	lang: 'zh-CN'
       		});
    });
</script>
</body>
</html>